package com.cheer.ba.presenter.impl;

import android.app.Dialog;
import android.content.Context;
import android.os.Handler;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;

import com.bigkoo.svprogresshud.SVProgressHUD;
import com.cheer.ba.R;
import com.cheer.ba.app.oss.OssManager;
import com.cheer.ba.app.oss.UploadPicManager;
import com.cheer.ba.cache.preference.EntityCache;
import com.cheer.ba.cache.preference.Session;
import com.cheer.ba.constant.CodeStatus;
import com.cheer.ba.constant.ConstantTag;
import com.cheer.ba.constant.Constants;
import com.cheer.ba.constant.ReturnCode;
import com.cheer.ba.http.BaseCallback;
import com.cheer.ba.http.CallManager;
import com.cheer.ba.http.HandleRetCode;
import com.cheer.ba.http.Http;
import com.cheer.ba.http.request.APIService;
import com.cheer.ba.model.LookMyBillModel;
import com.cheer.ba.model.OilCardInfoModel;
import com.cheer.ba.model.OilGoodsInfoModel;
import com.cheer.ba.model.OilMealModel;
import com.cheer.ba.model.OilSendModel;
import com.cheer.ba.model.PayInfoModel;
import com.cheer.ba.model.QyePayInfoModel;
import com.cheer.ba.model.ResponseData;
import com.cheer.ba.pay.PayCommon;
import com.cheer.ba.presenter.GeneralPresenter;
import com.cheer.ba.utils.AnalyzeParser;
import com.cheer.ba.utils.LogUtils;
import com.cheer.ba.utils.NetUtils;
import com.cheer.ba.utils.PullAnalyzeParser;
import com.cheer.ba.utils.StringUtils;
import com.cheer.ba.view.base.IViewController;
import com.cheer.ba.view.dialog.DialogUtils;
import com.litesuits.common.utils.HexUtil;
import com.litesuits.common.utils.MD5Util;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Response;

/**
 * 套餐充值数据处理
 *
 * @author HQ
 *         created at 2017/5/10 0010 15:32
 */
public class OilMealPresenter extends GeneralPresenter implements UploadPicManager.OnUploadCallback {

    private Context mContext;
    private IViewController mView;
    private APIService mUserService;
    private EntityCache<OilCardInfoModel> mCardCache;

    private AnalyzeParser parser;

    //oss上传
    private UploadPicManager mUpLoadPicManager;

    @Override
    public void attachView(IViewController view) {
        this.mView = view;
        mContext = getContext(view);
        mUserService = Http.getUserService(mContext);
        mCardCache = new EntityCache<>(mContext, OilCardInfoModel.class, "");
    }

    public void setmUpLoadPicManager() {
        mUpLoadPicManager = new UploadPicManager(this);
    }

    @Override
    public void detachView() {

    }

    @Override
    public Object getCacheData() {
        return null;
    }

    /**
     * 加油卡套餐列表
     */
    public void getOilCards() {
        if (!NetUtils.isNetworkConnected(mContext)) {
            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_NET, CodeStatus.Gegeneral.ERROR_NET);
            return;
        }
        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_LOADING, CodeStatus.Gegeneral.DATA_LOADING);
        Call<ResponseData<List<OilMealModel>>> call = mUserService.getOilCards(1002, "1");
        CallManager.add(call);
        call.enqueue(new BaseCallback<ResponseData<List<OilMealModel>>>() {
            @Override
            public void onResponse(Call<ResponseData<List<OilMealModel>>> call, Response<ResponseData<List<OilMealModel>>> response) {
                super.onResponse(call, response);
                if (response.isSuccessful()) {
                    ResponseData<List<OilMealModel>> res = response.body();
                    if (res.getRet() == ReturnCode.SUCCESS) {
                        List<OilMealModel> oilCards = res.getData();
                        if (null != oilCards) {
                            if (!oilCards.isEmpty()) {
                                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, CodeStatus.Gegeneral.DATA_SUCCESS_FULL);
                                mView.updateViewWithTag(oilCards, ConstantTag.GET_OIL_CARDS);
                            } else {
                                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_SUCCESS_NULL, CodeStatus.Gegeneral.DATA_SUCCESS_NULL);
                            }
                            return;
                        }
                    }
                }
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA);
            }

            @Override
            public void onFailure(Call<ResponseData<List<OilMealModel>>> call, Throwable t) {
                super.onFailure(call, t);
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA);
            }
        });
    }

    /**
     * 我的油卡列表
     *
     * @param isMain   1 拿默认 0 拿所有卡
     * @param provNamw 省份名称 "" 默认那所有
     */
    public void getMyOilCards(boolean isShow, final String isMain, String provNamw, String name, String tel, String plateNumber, String search) {
        if (!NetUtils.isNetworkConnected(mContext)) {
            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_NET, CodeStatus.Gegeneral.ERROR_NET, mContext.getString(R.string.no_net_work));
            return;
        }
        if (isShow) {
            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_LOADING, CodeStatus.Gegeneral.DATA_LOADING, mContext.getString(R.string.data_loading));
        }
        Call<ResponseData<List<OilCardInfoModel>>> call = mUserService.getMyOilCard(1002, Session.getUserId(), Session.getSessionKey(), isMain, "0", provNamw, name, tel, plateNumber, search);
        CallManager.add(call);
        call.enqueue(new BaseCallback<ResponseData<List<OilCardInfoModel>>>() {
            @Override
            public void onResponse(Call<ResponseData<List<OilCardInfoModel>>> call, Response<ResponseData<List<OilCardInfoModel>>> response) {
                super.onResponse(call, response);
                if (response.isSuccessful()) {
                    ResponseData<List<OilCardInfoModel>> res = response.body();
                    if (res.getRet() == ReturnCode.SUCCESS) {
                        List<OilCardInfoModel> oilCards = res.getData();
                        if (null != oilCards) {
                            if (!oilCards.isEmpty()) {
                                List<OilCardInfoModel> mCards = new ArrayList<OilCardInfoModel>();
                                for (OilCardInfoModel model : oilCards) {
                                    if (model.getCardStatus() != 3) {
                                        mCards.add(model);
                                    }
                                }
                                if (!mCards.isEmpty()) {
                                    mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, "");
                                    mView.updateViewWithTag(mCards, ConstantTag.MY_OIL_CARDS);
                                    if (TextUtils.equals("0", isMain)) {
                                        try {
                                            mCardCache.putListEntity(mCards);
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                        }
                                    }
                                } else {
                                    mCardCache.putListEntity(new ArrayList<OilCardInfoModel>());
                                    mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_SUCCESS_NULL, CodeStatus.Gegeneral.DATA_SUCCESS_NULL, "");
                                    mView.updateViewWithTag(CodeStatus.Gegeneral.DATA_SUCCESS_NULL, ConstantTag.DATA_SUCCESS_NULL);
                                }
                            } else {
                                mCardCache.putListEntity(new ArrayList<OilCardInfoModel>());
                                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_SUCCESS_NULL, CodeStatus.Gegeneral.DATA_SUCCESS_NULL, "");
                                mView.updateViewWithTag(CodeStatus.Gegeneral.DATA_SUCCESS_NULL, ConstantTag.DATA_SUCCESS_NULL);
                            }
                            return;
                        }
                    }
                }
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, mContext.getString(R.string.data_load_fail));
                mView.updateViewWithTag(CodeStatus.Gegeneral.ERROR_DATA, ConstantTag.DATA_ERROR);
            }

            @Override
            public void onFailure(Call<ResponseData<List<OilCardInfoModel>>> call, Throwable t) {
                super.onFailure(call, t);
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, mContext.getString(R.string.data_load_fail));
                mView.updateViewWithTag(CodeStatus.Gegeneral.ERROR_DATA, ConstantTag.DATA_ERROR);
            }
        });
    }

    /**
     * 设置为默认卡
     */
    public void setDefaultCard(String cardId) {
        if (!NetUtils.isNetworkConnected(mContext)) {
            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_NET, CodeStatus.Gegeneral.ERROR_NET, mContext.getString(R.string.no_net_work));
            return;
        }
        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_LOADING, CodeStatus.Gegeneral.DATA_LOADING, "");
        Call<ResponseData> call = mUserService.setDefaultCard(1002, Session.getSessionKey(), Session.getUserId(), cardId);
        CallManager.add(call);
        call.enqueue(new BaseCallback<ResponseData>() {
            @Override
            public void onResponse(Call<ResponseData> call, Response<ResponseData> response) {
                super.onResponse(call, response);
                if (response.isSuccessful()) {
                    ResponseData res = response.body();
                    if (res.getRet() == ReturnCode.SUCCESS) {
                        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, "");
                        mView.updateViewWithTag(true, ConstantTag.SET_DEFAULT_CARD);
                        return;
                    } else {
                        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "");
                        HandleRetCode.handler(mContext, res, true, "设置失败");
                        return;
                    }
                }
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "设置失败");
            }

            @Override
            public void onFailure(Call<ResponseData> call, Throwable t) {
                super.onFailure(call, t);
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "设置失败");
            }
        });
    }

    /**
     * 移除油卡
     */
    public void delOilCard(String cardId) {
        if (!NetUtils.isNetworkConnected(mContext)) {
            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_NET, CodeStatus.Gegeneral.ERROR_NET, mContext.getString(R.string.no_net_work));
            return;
        }
        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_LOADING, CodeStatus.Gegeneral.DATA_LOADING, mContext.getString(R.string.data_loading));
        Call<ResponseData> call = mUserService.delOilCard(1002, Session.getSessionKey(), Session.getUserId(), cardId);
        CallManager.add(call);
        call.enqueue(new BaseCallback<ResponseData>() {
            @Override
            public void onResponse(Call<ResponseData> call, Response<ResponseData> response) {
                super.onResponse(call, response);
                if (response.isSuccessful()) {
                    ResponseData res = response.body();
                    if (res.getRet() == ReturnCode.SUCCESS) {
                        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, "");
                        mView.updateViewWithTag(true, ConstantTag.DEL_OIL_CARD);
                        return;
                    } else {
                        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "");
                        HandleRetCode.handler(mContext, res, true, "移除失败");
                        return;
                    }
                }
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "移除失败");
            }

            @Override
            public void onFailure(Call<ResponseData> call, Throwable t) {
                super.onFailure(call, t);
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "移除失败");
            }
        });
    }

    /**
     * 绑定油卡
     */
    public void bindOilCard(String cardNum) {
        if (!NetUtils.isNetworkConnected(mContext)) {
            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_NET, CodeStatus.Gegeneral.ERROR_NET, mContext.getString(R.string.no_net_work));
            return;
        }
        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_LOADING, CodeStatus.Gegeneral.DATA_LOADING, mContext.getString(R.string.data_loading));
        Call<ResponseData<OilCardInfoModel>> call = mUserService.bindOilCard(1002, Session.getUserId(), cardNum);
        CallManager.add(call);
        call.enqueue(new BaseCallback<ResponseData<OilCardInfoModel>>() {
            @Override
            public void onResponse(Call<ResponseData<OilCardInfoModel>> call, Response<ResponseData<OilCardInfoModel>> response) {
                super.onResponse(call, response);
                if (response.isSuccessful()) {
                    ResponseData<OilCardInfoModel> res = response.body();
                    if (res.getRet() == ReturnCode.SUCCESS) {
                        OilCardInfoModel model = res.getData();
                        if (null != model) {
                            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, "");
                            mView.updateViewWithTag(model, ConstantTag.BIND_OIL_CARD);
                            return;
                        }
                    }
                }
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "");
                mView.updateViewWithTag("", ConstantTag.BIND_OIL_CARD_FAIL);
            }

            @Override
            public void onFailure(Call<ResponseData<OilCardInfoModel>> call, Throwable t) {
                super.onFailure(call, t);
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "");
                mView.updateViewWithTag("", ConstantTag.BIND_OIL_CARD_FAIL);
            }
        });
    }

    /**
     * 企业支付订单
     */
    public void qyePay(String couponId, String productId, String amount, String feeAmount) {
        if (!NetUtils.isNetworkConnected(mContext)) {
            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_NET, CodeStatus.Gegeneral.ERROR_NET, mContext.getString(R.string.no_net_work));
            return;
        }
        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_LOADING, CodeStatus.Gegeneral.DATA_LOADING, mContext.getString(R.string.data_loading));
        Call<ResponseData<QyePayInfoModel>> call = mUserService.getQyePayInfo(1002, couponId, "2", Session.getUserId(), productId, amount, feeAmount);
        CallManager.add(call);
        call.enqueue(new BaseCallback<ResponseData<QyePayInfoModel>>() {
            @Override
            public void onResponse(Call<ResponseData<QyePayInfoModel>> call, Response<ResponseData<QyePayInfoModel>> response) {
                super.onResponse(call, response);
                if (response.isSuccessful()) {
                    ResponseData<QyePayInfoModel> res = response.body();
                    if (res.getRet() == ReturnCode.SUCCESS) {
                        QyePayInfoModel model = res.getData();
                        if (null != model) {
                            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, "");
                            mView.updateViewWithTag(model, ConstantTag.QYE_PAY_SUCCESS);
                            return;
                        }
                    } else {
                        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "");
                        HandleRetCode.handler(mContext, res, true, "获取订单失败");
                        return;
                    }
                }
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "获取订单失败");
            }

            @Override
            public void onFailure(Call<ResponseData<QyePayInfoModel>> call, Throwable t) {
                super.onFailure(call, t);
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "获取订单失败");
            }
        });
    }

    /**
     * 企业划扣
     */
    public void qyePullMoney(String cardId, String toMoney) {
        if (!NetUtils.isNetworkConnected(mContext)) {
            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_NET, CodeStatus.Gegeneral.ERROR_NET, mContext.getString(R.string.no_net_work));
            return;
        }
        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_LOADING, CodeStatus.Gegeneral.DATA_LOADING, mContext.getString(R.string.data_loading));
        Call<ResponseData> call = mUserService.qYPullMoney(1002, Session.getUserId(), cardId, toMoney);
        CallManager.add(call);
        call.enqueue(new BaseCallback<ResponseData>() {
            @Override
            public void onResponse(Call<ResponseData> call, Response<ResponseData> response) {
                super.onResponse(call, response);
                if (response.isSuccessful()) {
                    ResponseData res = response.body();
                    if (res.getRet() == ReturnCode.SUCCESS) {
                        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, "");
                        mView.updateViewWithTag("", ConstantTag.QYE_PULL_SUCCESS);
                        return;
                    } else {
                        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "");
                        HandleRetCode.handler(mContext, res, true, "充值失败");
                        return;
                    }
                }
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "充值失败");
            }

            @Override
            public void onFailure(Call<ResponseData> call, Throwable t) {
                super.onFailure(call, t);
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "充值失败");
            }
        });
    }

    /**
     * 充值
     */
    public void rechargeCard(String productId, String amount, String feeAmount, String channel, String couponId) {
        if (!NetUtils.isNetworkConnected(mContext)) {
            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_NET, CodeStatus.Gegeneral.ERROR_NET, mContext.getString(R.string.no_net_work));
            return;
        }
        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_LOADING, CodeStatus.Gegeneral.DATA_LOADING, "");
        Call<ResponseData<PayInfoModel>> call = mUserService.getPayInfo(1002, Session.getSessionKey(), "2", productId, amount, feeAmount, channel, Session.getUserId(), couponId);
        CallManager.add(call);
        call.enqueue(new BaseCallback<ResponseData<PayInfoModel>>() {
            @Override
            public void onResponse(Call<ResponseData<PayInfoModel>> call, Response<ResponseData<PayInfoModel>> response) {
                super.onResponse(call, response);
                if (response.isSuccessful()) {
                    ResponseData<PayInfoModel> res = response.body();
                    if (res.getRet() == ReturnCode.SUCCESS) {
                        PayInfoModel model = res.getData();
                        if (null != model) {
                            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, "");
                            mView.updateViewWithTag(model, ConstantTag.RECHARGE_SUCCESS);
                            return;
                        }
                    } else {
                        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "");
                        HandleRetCode.handler(mContext, res, true, "获取订单失败");
                        return;
                    }
                }
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "获取订单失败");
            }

            @Override
            public void onFailure(Call<ResponseData<PayInfoModel>> call, Throwable t) {
                super.onFailure(call, t);
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "获取订单失败");
            }
        });
    }

    /**
     * 柴油批发
     */
    public void oilSend(String channel, String couponId, OilSendModel mOilSendModel) {
        if (!NetUtils.isNetworkConnected(mContext)) {
            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_NET, CodeStatus.Gegeneral.ERROR_NET, mContext.getString(R.string.no_net_work));
            return;
        }
        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_LOADING, CodeStatus.Gegeneral.DATA_LOADING, mContext.getString(R.string.data_loading));
        Call<ResponseData<PayInfoModel>> call = mUserService.getOilSendOrder(1002, channel, couponId, Session.getUserId(), mOilSendModel.supplyId, mOilSendModel.deliveryMode, mOilSendModel.buyNumber, mOilSendModel.throughTime, mOilSendModel.name, mOilSendModel.tel, mOilSendModel.location, StringUtils.removePoint(mOilSendModel.amount), mOilSendModel.feeAmount, mOilSendModel.orderSrc, mOilSendModel.remark);
        CallManager.add(call);
        call.enqueue(new BaseCallback<ResponseData<PayInfoModel>>() {
            @Override
            public void onResponse(Call<ResponseData<PayInfoModel>> call, Response<ResponseData<PayInfoModel>> response) {
                super.onResponse(call, response);
                if (response.isSuccessful()) {
                    ResponseData<PayInfoModel> res = response.body();
                    if (res.getRet() == ReturnCode.SUCCESS) {
                        PayInfoModel model = res.getData();
                        if (null != model) {
                            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, "");
                            mView.updateViewWithTag(model, ConstantTag.OIL_SEND_SUCCESS);
                            return;
                        }
                    } else {
                        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "");
                        HandleRetCode.handler(mContext, res, true, "获取订单失败");
                        return;
                    }
                }
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "获取订单失败");
            }

            @Override
            public void onFailure(Call<ResponseData<PayInfoModel>> call, Throwable t) {
                super.onFailure(call, t);
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "获取订单失败");
            }
        });
    }

    /**
     * 激活
     */
    public void activityOilCard(String amount, String feeAmount, String couponId) {
        if (!NetUtils.isNetworkConnected(mContext)) {
            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_NET, CodeStatus.Gegeneral.ERROR_NET, mContext.getString(R.string.no_net_work));
            return;
        }
        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_LOADING, CodeStatus.Gegeneral.DATA_LOADING, "");
        Call<ResponseData<PayInfoModel>> call = mUserService.activityOilCard(1002, couponId, "2", Session.getUserId(), amount, feeAmount);
        CallManager.add(call);
        call.enqueue(new BaseCallback<ResponseData<PayInfoModel>>() {
            @Override
            public void onResponse(Call<ResponseData<PayInfoModel>> call, Response<ResponseData<PayInfoModel>> response) {
                super.onResponse(call, response);
                if (response.isSuccessful()) {
                    ResponseData<PayInfoModel> res = response.body();
                    if (res.getRet() == ReturnCode.SUCCESS) {
                        PayInfoModel model = res.getData();
                        if (null != model) {
                            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, "");
                            mView.updateViewWithTag(model, ConstantTag.ACTIVITY_CARD_SUCCESS);
                            return;
                        }
                    } else {
                        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "");
                        HandleRetCode.handler(mContext, res, true, "获取订单失败");
                        return;
                    }
                }
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "获取订单失败");
            }

            @Override
            public void onFailure(Call<ResponseData<PayInfoModel>> call, Throwable t) {
                super.onFailure(call, t);
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "获取订单失败");
            }
        });
    }

    /**
     * 柴油批发回调
     */
    public void oilSendCallBack(String orderId) {
        if (!NetUtils.isNetworkConnected(mContext)) {
            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_NET, CodeStatus.Gegeneral.ERROR_NET, mContext.getString(R.string.no_net_work));
            return;
        }
        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_LOADING, CodeStatus.Gegeneral.DATA_LOADING, "");
        Call<ResponseData> call = mUserService.oilSendCallBack(1002, orderId, Session.getUserId());
        CallManager.add(call);
        call.enqueue(new BaseCallback<ResponseData>() {
            @Override
            public void onResponse(Call<ResponseData> call, Response<ResponseData> response) {
                super.onResponse(call, response);
                if (response.isSuccessful()) {
                    ResponseData res = response.body();
                    if (res.getRet() == ReturnCode.SUCCESS) {
                        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, "");
                        mView.updateViewWithTag(res.getRet(), ConstantTag.OIL_SEND_CALLBACK_SUCCESS);
                        return;
                    } else {
                        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "");
                        HandleRetCode.handler(mContext, res, true, "支付异常，请联系客服");
                        return;
                    }
                }
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "支付异常，请联系客服");
            }

            @Override
            public void onFailure(Call<ResponseData> call, Throwable t) {
                super.onFailure(call, t);
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "支付异常，请联系客服");
            }
        });
    }

    /**
     * 购买油卡
     */
    public void buyOilCard(String productId, String oilCardId, String orderId, String couponId) {
        if (!NetUtils.isNetworkConnected(mContext)) {
            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_NET, CodeStatus.Gegeneral.ERROR_NET, mContext.getString(R.string.no_net_work));
            return;
        }
        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_LOADING, CodeStatus.Gegeneral.DATA_LOADING, "");
        Call<ResponseData> call = mUserService.buyOilCard(1002, Session.getUserId(), productId, oilCardId, orderId, Session.getSessionKey(), couponId);
        CallManager.add(call);
        call.enqueue(new BaseCallback<ResponseData>() {
            @Override
            public void onResponse(Call<ResponseData> call, Response<ResponseData> response) {
                super.onResponse(call, response);
                if (response.isSuccessful()) {
                    ResponseData res = response.body();
                    if (res.getRet() == ReturnCode.SUCCESS) {
                        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, "");
                        mView.updateViewWithTag(res.getRet(), ConstantTag.DATA_SUCCESS_FULL);
                        return;
                    } else {
                        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "");
                        HandleRetCode.handler(mContext, res, true, "支付异常，请联系客服");
                        return;
                    }
                }
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "支付异常，请联系客服");
            }

            @Override
            public void onFailure(Call<ResponseData> call, Throwable t) {
                super.onFailure(call, t);
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "支付异常，请联系客服");
            }
        });
    }

    /**
     * 申请油卡
     */
    public void AskMyOilCards(String cardAddress, String cardId, String cardNum, String cardTel,
                              String cardType, String custName, String idUrl1, String idUrl2, String mCardNum) {
        if (!NetUtils.isNetworkConnected(mContext)) {
            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_NET, CodeStatus.Gegeneral.ERROR_NET, mContext.getString(R.string.no_net_work));
            return;
        }
        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_LOADING, CodeStatus.Gegeneral.DATA_LOADING, "");
        Call<ResponseData<OilCardInfoModel>> call = mUserService.AddMyOilCard(1002, cardAddress, cardId, cardNum, cardTel, cardType, Session.getUserId(), custName, idUrl1, idUrl2, "0", mCardNum);
        CallManager.add(call);
        call.enqueue(new BaseCallback<ResponseData<OilCardInfoModel>>() {
            @Override
            public void onResponse(Call<ResponseData<OilCardInfoModel>> call, Response<ResponseData<OilCardInfoModel>> response) {
                super.onResponse(call, response);
                if (response.isSuccessful()) {
                    ResponseData<OilCardInfoModel> res = response.body();
                    if (res.getRet() == ReturnCode.SUCCESS) {
                        OilCardInfoModel oilCards = res.getData();
                        if (null != oilCards) {
                            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, "");
                            mView.updateViewWithTag(oilCards, ConstantTag.ASK_OIL_CARD_SUCCESS);
                            return;
                        }
                    } else {
                        HandleRetCode.handler(mContext, res, true, "申请失败");
                        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "");
                        return;
                    }
                }
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "申请失败");
            }

            @Override
            public void onFailure(Call<ResponseData<OilCardInfoModel>> call, Throwable t) {
                super.onFailure(call, t);
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "申请失败");
            }
        });
    }

    /**
     * 投诉与建议
     */
    public void mySuggest(String title, String context, String url) {
        if (!NetUtils.isNetworkConnected(mContext)) {
            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_NET, CodeStatus.Gegeneral.ERROR_NET, mContext.getString(R.string.no_net_work));
            return;
        }
        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_LOADING, CodeStatus.Gegeneral.DATA_LOADING, "");
        Call<ResponseData> call = mUserService.mySuggest(1002, Session.getUserId(), title, context, "", url);
        CallManager.add(call);
        call.enqueue(new BaseCallback<ResponseData>() {
            @Override
            public void onResponse(Call<ResponseData> call, Response<ResponseData> response) {
                super.onResponse(call, response);
                if (response.isSuccessful()) {
                    ResponseData res = response.body();
                    if (res.getRet() == ReturnCode.SUCCESS) {
                        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, "");
                        mView.updateViewWithTag(ReturnCode.SUCCESS, ConstantTag.SUGGEST_SUCCESS);
                        return;
                    } else {
                        HandleRetCode.handler(mContext, res, true, "提交失败");
                        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "");
                        return;
                    }
                }
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "提交失败");
            }

            @Override
            public void onFailure(Call<ResponseData> call, Throwable t) {
                super.onFailure(call, t);
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, " 提交失败");
            }
        });
    }

    /**
     * 添加账本
     */
    public void addMyBooks(String money, String title, String content, String url, String logType) {
        if (!NetUtils.isNetworkConnected(mContext)) {
            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_NET, CodeStatus.Gegeneral.ERROR_NET, mContext.getString(R.string.no_net_work));
            return;
        }
        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_LOADING, CodeStatus.Gegeneral.DATA_LOADING, "");
        Call<ResponseData<LookMyBillModel>> call = mUserService.addMyBooks(1002, Session.getUserId(), title, content, url, "", "1", money, logType);
        CallManager.add(call);
        call.enqueue(new BaseCallback<ResponseData<LookMyBillModel>>() {
            @Override
            public void onResponse(Call<ResponseData<LookMyBillModel>> call, Response<ResponseData<LookMyBillModel>> response) {
                super.onResponse(call, response);
                if (response.isSuccessful()) {
                    ResponseData<LookMyBillModel> res = response.body();
                    if (res.getRet() == ReturnCode.SUCCESS) {
                        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, "");
                        mView.updateViewWithTag(ReturnCode.SUCCESS, ConstantTag.SUGGEST_SUCCESS);
                        return;
                    } else {
                        HandleRetCode.handler(mContext, res, true, "添加失败");
                        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "");
                        return;
                    }
                }
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "添加失败");
            }

            @Override
            public void onFailure(Call<ResponseData<LookMyBillModel>> call, Throwable t) {
                super.onFailure(call, t);
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "添加失败");
            }
        });
    }

    /**
     * 校验登录密码
     */
    public void checkLoginPw(final String pw) {
        if (!NetUtils.isNetworkConnected(mContext)) {
            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_NET, CodeStatus.Gegeneral.ERROR_NET, mContext.getString(R.string.no_net_work));
            return;
        }
        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_LOADING, CodeStatus.Gegeneral.DATA_LOADING, mContext.getString(R.string.data_loading));
        Call<ResponseData> call = mUserService.checkLoginPw(1002, Session.getUserPhone(), pw);
        CallManager.add(call);
        call.enqueue(new BaseCallback<ResponseData>() {
            @Override
            public void onResponse(Call<ResponseData> call, Response<ResponseData> response) {
                super.onResponse(call, response);
                if (response.isSuccessful()) {
                    ResponseData res = response.body();
                    if (res.getRet() == ReturnCode.SUCCESS) {
                        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, "");
                        mView.updateViewWithTag(pw, ConstantTag.CHECK_PW_SUCCESS);
                        return;
                    } else {
                        HandleRetCode.handler(mContext, res, true, "密码校验失败");
                        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "");
                        return;
                    }
                }
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "密码校验失败");
            }

            @Override
            public void onFailure(Call<ResponseData> call, Throwable t) {
                super.onFailure(call, t);
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "密码校验失败");
            }
        });
    }

    /**
     * 企业柴油支付回调
     */
    public void qyePayCallBack(String packageId, String cardId, String orderId, String couponId) {
        if (!NetUtils.isNetworkConnected(mContext)) {
            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_NET, CodeStatus.Gegeneral.ERROR_NET, mContext.getString(R.string.no_net_work));
            return;
        }
        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_LOADING, CodeStatus.Gegeneral.DATA_LOADING, "");
        Call<ResponseData> call = mUserService.getQyePayCallBack(1002, Session.getUserId(), packageId, cardId, orderId, couponId);
        CallManager.add(call);
        call.enqueue(new BaseCallback<ResponseData>() {
            @Override
            public void onResponse(Call<ResponseData> call, Response<ResponseData> response) {
                super.onResponse(call, response);
                if (response.isSuccessful()) {
                    ResponseData res = response.body();
                    if (res.getRet() == ReturnCode.SUCCESS) {
                        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, "");
                        mView.updateViewWithTag(res.getRet(), ConstantTag.DATA_SUCCESS_FULL);
                        return;
                    } else {
                        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "");
                        HandleRetCode.handler(mContext, res, true, "支付异常，请联系客服");
                        return;
                    }
                }
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "支付异常，请联系客服");
            }

            @Override
            public void onFailure(Call<ResponseData> call, Throwable t) {
                super.onFailure(call, t);
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "支付异常，请联系客服");
            }
        });
    }

    /**
     * 油品来源分类
     */
    public void getOilType() {
        if (!NetUtils.isNetworkConnected(mContext)) {
            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_NET, CodeStatus.Gegeneral.ERROR_NET);
            return;
        }
        Call<ResponseData<List<OilGoodsInfoModel>>> call = mUserService.getOilTypeList(1508);
        CallManager.add(call);
        call.enqueue(new BaseCallback<ResponseData<List<OilGoodsInfoModel>>>() {
            @Override
            public void onResponse(Call<ResponseData<List<OilGoodsInfoModel>>> call, Response<ResponseData<List<OilGoodsInfoModel>>> response) {
                super.onResponse(call, response);
                if (response.isSuccessful()) {
                    ResponseData<List<OilGoodsInfoModel>> res = response.body();
                    if (res.getRet() == ReturnCode.SUCCESS) {
                        List<OilGoodsInfoModel> qyes = res.getData();
                        if (null != qyes) {
                            if (!qyes.isEmpty()) {
                                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, CodeStatus.Gegeneral.DATA_SUCCESS_FULL);
                                mView.updateViewWithTag(qyes, ConstantTag.GET_OIL_TYPE_LIST);
                            }
                            return;
                        }
                    }
                }
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA);
            }

            @Override
            public void onFailure(Call<ResponseData<List<OilGoodsInfoModel>>> call, Throwable t) {
                super.onFailure(call, t);
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA);
            }
        });
    }

    //记录当前分页下标
    private int mRecordPage = 0;
    private int mIndex = 0;

    //数据是否加载失败
    private boolean isDataError = false;

    /**
     * 获得司机列表
     *
     * @param loadMore
     */
    public void getDriverList(boolean isShowLoad, final boolean loadMore, String name, String plateNumber, String tel, String cardId, String search) {
        if (!NetUtils.isNetworkConnected(mContext)) {
            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_NET, CodeStatus.Gegeneral.ERROR_NET, "", loadMore);
            return;
        }
        if (!loadMore) {
            isDataError = false;
            mRecordPage = 0;
        } else {
            if (isDataError) {
                mRecordPage = mIndex;
            } else {
                mRecordPage += Constants.PAGESIZE;
            }
        }
        mIndex = mRecordPage;
        if (isShowLoad) {
            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_LOADING, CodeStatus.Gegeneral.DATA_LOADING, "", loadMore);
        }
        Call<ResponseData<List<OilCardInfoModel>>> call = mUserService.getDriverList(1508, Session.getUserId(), name, plateNumber, tel, cardId, mRecordPage, Constants.PAGESIZE, search);
        CallManager.add(call);
        call.enqueue(new BaseCallback<ResponseData<List<OilCardInfoModel>>>() {
            @Override
            public void onResponse(Call<ResponseData<List<OilCardInfoModel>>> call, Response<ResponseData<List<OilCardInfoModel>>> response) {
                super.onResponse(call, response);
                if (response.isSuccessful()) {
                    ResponseData<List<OilCardInfoModel>> res = response.body();
                    if (res.getRet() == ReturnCode.SUCCESS) {
                        List<OilCardInfoModel> articles = res.getData();
                        if (null != articles) {
                            if (articles.isEmpty()) {
                                isDataError = true;
                                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_SUCCESS_NULL, CodeStatus.Gegeneral.DATA_SUCCESS_NULL, "", loadMore);
                            } else {
                                isDataError = false;
                                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, "", loadMore);
                            }
                            mView.updateViewWithLoadMore(articles, loadMore, ConstantTag.GET_DRIVERS_LIST);
                            return;
                        }
                    }
                }
                isDataError = true;
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "", loadMore);
            }

            @Override
            public void onFailure(Call<ResponseData<List<OilCardInfoModel>>> call, Throwable t) {
                super.onFailure(call, t);
                isDataError = true;
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "", loadMore);
            }
        });
    }

    /**
     * 添加司机
     */
    public void addDriverInfo(String name, String plateNumber, String tel, String cardId, String cardNum) {
        if (!NetUtils.isNetworkConnected(mContext)) {
            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_NET, CodeStatus.Gegeneral.ERROR_NET, mContext.getString(R.string.no_net_work));
            return;
        }
        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_LOADING, CodeStatus.Gegeneral.DATA_LOADING, mContext.getString(R.string.data_loading));
        Call<ResponseData> call = mUserService.addDriver(1002, Session.getUserId(), name, plateNumber, tel, cardId, cardNum);
        CallManager.add(call);
        call.enqueue(new BaseCallback<ResponseData>() {
            @Override
            public void onResponse(Call<ResponseData> call, Response<ResponseData> response) {
                super.onResponse(call, response);
                if (response.isSuccessful()) {
                    ResponseData res = response.body();
                    if (res.getRet() == ReturnCode.SUCCESS) {
                        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, "");
                        mView.updateViewWithTag(res.getRet(), ConstantTag.ADD_DRIVERS);
                        return;
                    } else {
                        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "");
                        HandleRetCode.handler(mContext, res, true, "添加失败");
                        return;
                    }
                }
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "添加失败");
            }

            @Override
            public void onFailure(Call<ResponseData> call, Throwable t) {
                super.onFailure(call, t);
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "添加失败");
            }
        });
    }

    /**
     * 移除司机
     */
    public void delDriverInfo(String driverId) {
        if (!NetUtils.isNetworkConnected(mContext)) {
            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_NET, CodeStatus.Gegeneral.ERROR_NET, mContext.getString(R.string.no_net_work));
            return;
        }
        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_LOADING, CodeStatus.Gegeneral.DATA_LOADING, mContext.getString(R.string.data_loading));
        Call<ResponseData<OilCardInfoModel>> call = mUserService.delDriver(1002, Session.getUserId(), driverId);
        CallManager.add(call);
        call.enqueue(new BaseCallback<ResponseData<OilCardInfoModel>>() {
            @Override
            public void onResponse(Call<ResponseData<OilCardInfoModel>> call, Response<ResponseData<OilCardInfoModel>> response) {
                super.onResponse(call, response);
                if (response.isSuccessful()) {
                    ResponseData<OilCardInfoModel> res = response.body();
                    if (res.getRet() == ReturnCode.SUCCESS) {
                        OilCardInfoModel model = res.getData();
                        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, "");
                        mView.updateViewWithTag(model, ConstantTag.DEL_DRIVERS);
                        return;
                    } else {
                        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "");
                        HandleRetCode.handler(mContext, res, true, "移除失败");
                        return;
                    }
                }
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "移除失败");
            }

            @Override
            public void onFailure(Call<ResponseData<OilCardInfoModel>> call, Throwable t) {
                super.onFailure(call, t);
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "移除失败");
            }
        });
    }

    /**
     * 绑定司机
     */
    public void bindDriverInfo(String driverId, String cardNum) {
        if (!NetUtils.isNetworkConnected(mContext)) {
            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_NET, CodeStatus.Gegeneral.ERROR_NET, mContext.getString(R.string.no_net_work));
            return;
        }
        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_LOADING, CodeStatus.Gegeneral.DATA_LOADING, mContext.getString(R.string.data_loading));
        Call<ResponseData<OilCardInfoModel>> call = mUserService.bindDriver(1002, Session.getUserId(), driverId, cardNum);
        CallManager.add(call);
        call.enqueue(new BaseCallback<ResponseData<OilCardInfoModel>>() {
            @Override
            public void onResponse(Call<ResponseData<OilCardInfoModel>> call, Response<ResponseData<OilCardInfoModel>> response) {
                super.onResponse(call, response);
                if (response.isSuccessful()) {
                    ResponseData<OilCardInfoModel> res = response.body();
                    if (res.getRet() == ReturnCode.SUCCESS) {
                        OilCardInfoModel model = res.getData();
                        if (null != model) {
                            mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, CodeStatus.Gegeneral.DATA_SUCCESS_FULL, "");
                            mView.updateViewWithTag(model, ConstantTag.BIND_DRIVERS);
                            return;
                        }
                    } else {
                        mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "");
                        HandleRetCode.handler(mContext, res, true, "绑定失败");
                        return;
                    }
                }
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "绑定失败");
            }

            @Override
            public void onFailure(Call<ResponseData<OilCardInfoModel>> call, Throwable t) {
                super.onFailure(call, t);
                mView.onLoadingStatus(mView, false, CodeStatus.Gegeneral.ERROR_DATA, CodeStatus.Gegeneral.ERROR_DATA, "绑定失败");
            }
        });
    }

    /**
     * 显示支付弹出框
     */
    public void showPayDialog() {
        final View payViwe = LayoutInflater.from(mContext).inflate(R.layout.dialog_check_pw, null);
        final EditText mEditPw = (EditText) payViwe.findViewById(R.id.id_check_pw_edit);
        final Dialog mDialog = DialogUtils.selfDialog(mContext, payViwe, true);
        mDialog.show();
        payViwe.findViewById(R.id.id_check_cancel_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mDialog.dismiss();
                hideSoft(payViwe);
            }
        });
        payViwe.findViewById(R.id.id_check_sure_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String pw = mEditPw.getText().toString().trim();
                if (StringUtils.isEmpty(pw)) {
                    SVProgressHUD.showInfoWithStatus(mContext, "请输入登录密码");
                } else {
                    checkLoginPw(HexUtil.encodeHexStr(MD5Util.md5(pw)));
                }
                mDialog.dismiss();
                hideSoft(payViwe);
            }
        });
    }

    /**
     * 隐藏键盘
     */
    public void hideSoft(final View v) {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
            }
        }, 10);
    }

    /**
     * @param flag     1 拿充值金额 2 拿折扣 3 拿付款方式 4获得省级数据 5获得市级数据 6 获得地区级数据
     * @param isShowQy 是否添加企业支付
     * @return
     */
    public Object getData(int flag, boolean isShowQy) {
        if (flag == 1) {
            OilMealModel model = new OilMealModel();
            model.setMinPrice(200);
            model.setMaxPrice(20000);
            model.setMiddlePrice(1000);
            model.setIncreasePrice(100);
            model.setmOilName("中国石油");
            model.setmOilType("加油卡");
            model.setIsDefault(0);
            model.setmOilCardNum("**** **** **** 6744");
            return model;
        } else if (flag == 2) {
            List<OilMealModel> meals = new ArrayList<OilMealModel>();
            OilMealModel meal1 = new OilMealModel();
            meal1.setMoney("20000");
            meal1.setDiscount("0.98");
            OilMealModel meal2 = new OilMealModel();
            meal2.setMoney("50000");
            meal2.setDiscount("0.98");
            OilMealModel meal3 = new OilMealModel();
            meal3.setMoney("100000");
            meal3.setDiscount("0.98");
            OilMealModel meal4 = new OilMealModel();
            meal4.setMoney("200000");
            meal4.setDiscount("0.98");
            OilMealModel meal5 = new OilMealModel();
            meal5.setMoney("300000");
            meal5.setDiscount("0.98");
            OilMealModel meal6 = new OilMealModel();
            meal6.setMoney("500000");
            meal6.setDiscount("0.98");
            meals.add(meal1);
            meals.add(meal2);
            meals.add(meal3);
            meals.add(meal4);
            meals.add(meal5);
            meals.add(meal6);
            return meals;
        } else if (flag == 3) {
            List<PayInfoModel> mPayWays = new ArrayList<PayInfoModel>();
            if (TextUtils.equals("3", Session.getUserOrgType())) {
                //企业
                PayInfoModel model4 = new PayInfoModel();
                model4.setPayLogo(R.drawable.ic_qiye_pay);
                model4.setPayTitle(mContext.getString(R.string.qiye_pay));
                model4.setPayDesc(mContext.getString(R.string.qiye_pay_desc));
                model4.setPayWay(PayCommon.QIYE_PAY);
                mPayWays.add(model4);
            } else {
                PayInfoModel model = new PayInfoModel();
                model.setPayLogo(R.drawable.ic_pay_ali_way);
                model.setPayTitle(mContext.getString(R.string.apli_pay));
                model.setPayDesc(mContext.getString(R.string.apli_pay_desc));
                model.setPayWay(PayCommon.CHANNEL_ALIPAY);
                PayInfoModel model2 = new PayInfoModel();
                model2.setPayLogo(R.drawable.ic_pay_wx_logo);
                model2.setPayTitle(mContext.getString(R.string.wx_pay));
                model2.setPayDesc(mContext.getString(R.string.wx_pay_desc));
                model2.setPayWay(PayCommon.CHANNEL_WECHAT);
                mPayWays.add(model);
                mPayWays.add(model2);
            }


//            PayInfoModel model3 = new PayInfoModel();
//            model3.setPayLogo(R.drawable.ic_pay_yinlian_way);
//            model3.setPayTitle(mContext.getString(R.string.upacp_pay));
//            model3.setPayDesc(mContext.getString(R.string.upacp_pay_desc));
//            model3.setPayWay(PayCommon.CHANNEL_UPACP);
//            mPayWays.add(model3);

            return mPayWays;
        } else if (flag == 4) {
            try {
                InputStream is = mContext.getAssets().open("Provinces.xml");
                parser = new PullAnalyzeParser();
                return parser.provinces(is);
            } catch (Exception e) {
                e.printStackTrace();
                LogUtils.LogD("error", e.getMessage() + "--------");
            }
        } else if (flag == 5) {
            try {
                InputStream is = mContext.getAssets().open("Cities.xml");
                parser = new PullAnalyzeParser();
                return parser.citys(is);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if (flag == 6) {
            try {
                InputStream is = mContext.getAssets().open("Districts.xml");
                parser = new PullAnalyzeParser();
                return parser.districts(is);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return null;
    }

    /**
     * 上传图片
     */
    public void uploadPic(List<String> filePaths, ImageView mImgView) {
        SVProgressHUD.showWithStatus(mContext, "请求数据中...");
        List<UploadPicManager.UploadInfo> dataList = new ArrayList<UploadPicManager.UploadInfo>();
        /**
         * oss上传图片，得到回调之后，保存图片地址到本地
         */
        for (String path : filePaths) {
            UploadPicManager.UploadInfo info = new UploadPicManager.UploadInfo();
            info.fileSavePath = path;
            dataList.add(info);
        }
        mUpLoadPicManager.compressAndUploads(mContext, dataList, OssManager.OTHER_PIC, mImgView);
    }

    /**
     * 上传视频
     */
    public void uploadPic(List<String> filePaths) {
        SVProgressHUD.showWithStatus(mContext, "请求数据中...");
        List<UploadPicManager.UploadInfo> dataList = new ArrayList<UploadPicManager.UploadInfo>();
        /**
         * oss上传图片，得到回调之后，保存图片地址到本地
         */
        for (String path : filePaths) {
            UploadPicManager.UploadInfo info = new UploadPicManager.UploadInfo();
            info.fileSavePath = path;
            dataList.add(info);
        }
        mUpLoadPicManager.compressAndUploads(mContext, dataList, OssManager.VIDEO, null);
    }

    @Override
    public void onResult(boolean flag, List<UploadPicManager.UploadInfo> resultList) {
        LogUtils.LogD("图片上传", flag + "-=-=-=-=-=" + resultList.toString());
//        SVProgressHUD.dismiss(mContext);
        LogUtils.LogD("判定", "------" + flag);
        if (flag) {
            mView.updateViewWithTag(resultList, ConstantTag.HEADPIC_UP_SUCCESS);
        } else {
            mView.updateViewWithTag(null, ConstantTag.HEADPIC_UP_FAIL);
        }
    }
}
